﻿using System.Web;
using System.Web.Mvc;

namespace Echegoyen
{
    public class FilterConfig
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new LoggingExceptionFilter(new HandleErrorAttribute(), DependencyResolver.Current.GetService<IMyLogger>()));
            //filters.Add(new HandleErrorAttribute());
        }
    }


    public class LoggingExceptionFilter : IExceptionFilter
    {
        private readonly IExceptionFilter _filter;

        private readonly IMyLogger _logWriter;

        public LoggingExceptionFilter(IExceptionFilter filter, IMyLogger logWriter)
        {
            _filter = filter;
            _logWriter = logWriter;
        }

        public void OnException(ExceptionContext filterContext)
        {
            _logWriter.Error("Aplicación", "Error general", filterContext.Exception);
            _filter.OnException(filterContext);
        }
    }
}